{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b0c529c6",
   "metadata": {},
   "source": [
    "# 4.4.2 Workplanes\n",
    "\n",
    "Workplanes allow 2D construction on planes in 3D space. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f336cd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from netgen.occ import *\n",
    "from netgen.webgui import Draw as DrawGeo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37a286ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp = WorkPlane()\n",
    "wp.Rectangle(5,2)\n",
    "face = wp.Face()\n",
    "DrawGeo(face);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "452a55b4",
   "metadata": {},
   "source": [
    "A workplane is defined by a local coordinate system given by an 'Axes' object. This is specified by its origin, the normal vector to the plane, and the horizontal direction (i.e. the local x direction)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4110895d",
   "metadata": {},
   "outputs": [],
   "source": [
    "f1 = WorkPlane(Axes((0,0,0), n=Z, h=X)).Rectangle(2,1).Face()\n",
    "f2 = WorkPlane(Axes((0,1,0), n=-Y, h=X)).Rectangle(2,1).Face()\n",
    "f3 = WorkPlane(Axes((0,0,0), n=X, h=Y)).Rectangle(1,1).Face()\n",
    "DrawGeo (f1+f2+f3);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a72b5065",
   "metadata": {},
   "source": [
    "The workplane stores the current position and direction. With `Line` we draw a straight line of given length in the current direction, with `Arc` we draw a tangential arc of given radius and angle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dc550f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp = WorkPlane()\n",
    "for i in range(6):\n",
    "    wp.Line(1).Rotate(60)\n",
    "wp.MoveTo(3,0)\n",
    "for i in range(6):\n",
    "    wp.Line(0.6).Arc(0.4, 60)\n",
    "face = wp.Face()\n",
    "DrawGeo(face);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9914f1b9",
   "metadata": {},
   "source": [
    "We can draw several wires. Holes a defined by reveriting the orientation of an wire:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60e821f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "wp=WorkPlane().RectangleC(2,1) \\\n",
    "    .Circle(0.5,0,0.2).Reverse() \\\n",
    "    .Circle(-0.5,0,0.2).Reverse()\n",
    "DrawGeo(Compound(wp.Wires()))\n",
    "DrawGeo(wp.Face());"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8422475f",
   "metadata": {},
   "source": [
    "Faces can be extruded"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfe7d7a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "face = WorkPlane().RectangleC(2,1).RectangleC(1.8,0.8).Reverse().Face()\n",
    "frame = face.Extrude(1)\n",
    "DrawGeo(frame);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "795d3701",
   "metadata": {},
   "source": [
    "and also revolved:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "396bbaca",
   "metadata": {},
   "outputs": [],
   "source": [
    "face = WorkPlane().MoveTo(10,0).Line(18).Arc(2,90).Line(6).Arc(2,90) \\\n",
    "    .Line(18).Rotate(90).Line(2).Rotate(90).Line(10) \\\n",
    "    .Arc(3,-180).Line(10).Close().Face()\n",
    "p = face.Revolve(Axis((0,0,0),Y),180)\n",
    "DrawGeo(p);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8accbe3d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
